package cn.edu.scau.Servlet;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;

public class MyServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

		doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

		resp.setContentType("text/html;charset=UTF-8");

		// 获取文件名
		String filepath = req.getParameter("path");

		int index = filepath.lastIndexOf("\\");

		String filename = filepath.substring(index+1);

		System.out.println(filename);

		// 获得上传的文件并且保存
		Part part = req.getPart("file");

		part.write("g:/" + filename);

	}

}
